﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Billing.Controls
{
    /// <summary>
    /// Interaction logic for TMCDateTimePicker.xaml
    /// </summary>
    public partial class TMCDateTimePicker
    {
        public TMCDateTimePicker()
        {
            InitializeComponent();

            DefaultDateTime = DateTime.Now;
        }

        public DateTime DefaultDateTime
        {
            set
            {
                nudDate.DefaultValue = value.Day;
                nudMonth.DefaultValue = value.Month;
                nudYear.DefaultValue = value.Year;
                nudHours.DefaultValue = value.Hour;
            }
        }

        public void FocusOnDate()
        {
            nudDate.FocusOnText();
        }

        private void nudDate_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                nudMonth.FocusOnText();
            }
        }

        private void nudMonth_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                nudYear.FocusOnText();
            }
        }

        private void nudYear_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && nudHours.Visibility == Visibility.Visible)
            {
                nudHours.FocusOnText();
            }
        }

        public DateTime MinimumDate
        {
            set
            {
                nudDate.Minimum = 1;
                nudMonth.Minimum = 1;
                nudYear.Minimum = value.Year;
                nudHours.Minimum = 1;
            }
        }

        public DateTime SelectedDateTime
        {
            get
            {
                return new System.DateTime(nudDate.Value, nudMonth.Value, nudYear.Value, nudHours.Value, 0, 0);
            }
        }

        public bool IsFocusedOnHours
        {
            get
            {
                return nudHours.txtBoxValue.IsFocused;
            }
        }

        public bool IsFocusedOnDate
        {
            get
            {
                return nudDate.txtBoxValue.IsFocused;
            }
        }

        public bool IsFocusedOnMonth
        {
            get
            {
                return nudMonth.txtBoxValue.IsFocused;
            }
        }

        public bool IsFocusedOnYear
        {
            get
            {
                return nudYear.txtBoxValue.IsFocused;
            }
        }

        public void SetFocusOnDate()
        {
            nudDate.txtBoxValue.Focus();
        }

        public void SetFocusOnMonth()
        {
            nudMonth.txtBoxValue.Focus();
        }

        public void SetFocusOnYear()
        {
            nudYear.txtBoxValue.Focus();
        }

        public void SetFocusOnHours()
        {
            nudHours.txtBoxValue.Focus();
        }

        public void SetHoursInvisible()
        {
            nudHours.Visibility = Visibility.Collapsed;
        }
    }
}
